import { env } from "./envs"
/**
 * 
 * @param {String} url 
 * @param {Object} data 
 * @param {"GET"|"POST"} type_ 
 * @returns 
 */
export default function re(url, data, type_) {
    /**
     * 
     * @param {String} type_ 
     * @returns {String}
     */
    const get_type = (type_) => {
        type_ = type_.toUpperCase()
        return type_=="GET"?"GET":"POST"
        
    }
    
    return new Promise((resolve, reject) => {
        $.ajax({
            type: get_type(type_),
            url: env.host + url,
            dataType: "json",
            timeout: 500,
            headers: {
                "Content-Type": "application/json"
            },
            success(msg) {
                resolve(msg.data)
            },
            error(msg) {
                reject(msg.responseText)
            },
            data: get_type(type_) === "POST" ? JSON.stringify(data) : data

        })

    })
}


